require('weui');
require('font-awesome/css/font-awesome.css');
require('./index.css');

const moment = require('moment');

(function(doc, win) {
	var docEl = doc.documentElement,
		resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
		recalc = function() {
			var clientWidth = docEl.clientWidth;
			if (!clientWidth) return;
			if (clientWidth > 640) {
				clientWidth = 640;
			}
			docEl.style.fontSize = 10 * (clientWidth / 320) + 'px';

		};

	if (!doc.addEventListener) return;
	win.addEventListener(resizeEvt, recalc, false);
	doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);


require('video.js/dist/video-js.css');
require('video.js/dist/lang/zh-CN');
const SWF_PATH = require('video.js/dist/video-js.swf');
videojs.options.flash.swf = SWF_PATH;
const VTTJS_PATH = require('file!videojs-vtt.js/dist/vtt.min.js');
videojs.options['vtt.js'] = VTTJS_PATH;
//require('videojs-contrib-media-sources');
//require('videojs-contrib-hls');
window.videojs = videojs;
require('videojs-contrib-hls/dist/videojs-contrib-hls.js');

riot.mixin({
	observable: riot.observable(),
	extend: function(des, src, override) {
		if (src instanceof Array) {
			for (var i = 0, len = src.length; i < len; i++)
				this.extend(des, src[i], override);
		}
		for (var i in src) {
			if (override || !(i in des)) {
				des[i] = src[i];
			}
		}
		return des;
	},
	isEmptyObject: function(e) {
		var t;
		for (t in e)
			return !1;
		return !0
	},
	dateFormat: function(_date, _format) {
		return moment(_date).format(_format);
	},
	timestampFormat: function(_timestamp, _format) {
		return this.dateFormat(new Date(moment.unix(_timestamp / 1000)), _format);
	},
	getTimestamp: function() {
		return moment().format('x');
	},
	setUserInfo: function(userInfo) {
		cookies.set('userInfo', userInfo);
	},
	getUserInfo: function() {
		return cookies.getJSON('userInfo');
	},
	setRobotInfo: function(robotInfo) {
		cookies.set('robotInfo', robotInfo);
	},
	getRobotInfo: function() {
		return cookies.getJSON('robotInfo');
	},
	ws: {
		ask: 'http://10.201.11.204:9090/api/robot/answer'
	},
	consts: {
		inputDisabled: false
	}
});

require('./pages/app.tag');
require('./pages/layout/app-header.tag');
require('./pages/layout/app-view.tag');
require('./pages/layout/app-input.tag');

riot.mount('app');